package com.hyk.controller;


import com.hyk.dto.ApiResult;
import com.hyk.entity.Menu;
import com.hyk.entity.response.MenuListResponse;
import com.hyk.service.IMenuService;
import com.hyk.utils.R;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hyk
 * @since 2021-03-16
 */
@RestController
@RequestMapping("/menu")
@Api(tags = "菜单管理")
@CrossOrigin
public class MenuController {

    @Resource
    private IMenuService menuService;

    @PostMapping("/add")
    public ApiResult add(@RequestBody Menu menu){
        menu.setCreateTime(new Date());
        menu.setUpdateTime(new Date());
        menuService.addMenu(menu);
        return R.ok();
    }

    @PostMapping("/listMenu")
    public ApiResult listMenu(){
        List<MenuListResponse> menuListResponses = menuService.selectMenu();
        return R.ok(menuListResponses);
    }

}
